package com.bwie.service.Impl;

import com.bwie.dto.ProdFileDto;
import com.bwie.utils.JwtsUtils;
import com.bwie.utils.R;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.ProdFileMapper;
import com.bwie.domain.ProdFile;
import com.bwie.service.ProdFileService;

import javax.servlet.http.HttpServletRequest;

@Service
public class ProdFileServiceImpl extends ServiceImpl<ProdFileMapper, ProdFile> implements ProdFileService{

    @Autowired
    private ProdFileMapper prodFileMapper;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private HttpServletRequest request;

    @Override
    public R saveProdFile(ProdFileDto prodFileDto) {
        // 初始化 审计字段
        String token = request.getHeader("token");
        Integer idByToken = JwtsUtils.getIdByToken(token);

        ProdFile prodFile = new ProdFile();
        prodFile.setCreateBy(idByToken);
        prodFile.setCreateDate(new Date());
        prodFile.setDeleteFlag(0);
        // Dto参数传递
        BeanUtils.copyProperties(prodFileDto,prodFile);

        // 新增
        prodFileMapper.insert(prodFile);

        // 返回前端
        return R.OK();
    }
}
